import { ElNotification } from "element-plus";
import { message } from "@/utils/Element";
import { writeText } from "@tauri-apps/api/clipboard";


// 复制的 hook
export default async (input: string, isTip = true) => {
	try {
		if (import.meta.env.VITE_IS_TAURI) {
			// tauri-api 环境
			await writeText(input);
		} else {
			await navigator.clipboard.writeText(input);
		}
		// isTip && message.success("复制成功: " + input);
		if (isTip) {
			ElNotification({
				message: "复制成功",
				type: "success",
				offset: 40
			});
		}
	} catch (error: unknown) {
		if (error instanceof Error) {
			message.error(error.message);
		}
	}
};
